package com.pc.controller;

import com.pc.enrty.Order;
import com.pc.enrty.Pay;
import com.pc.enrty.ShoppingAddress;
import com.pc.enrty.ShoppingTrolley;
import com.pc.pojo.OrderSet;
import com.pc.service.OrderService;
import com.pc.service.PayService;
import com.pc.service.ShoppingAddressService;
import com.pc.service.ShoppingTrolleyService;
import com.pc.util.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/order/")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private ResultObject result;

    @RequestMapping("addorder")
    public ResultObject addorder(Order order){
        boolean b = orderService.addOrder(order);
        if(b){
            result.setStatus(400);
            result.setResult("注册成功");
        }else{
            result.setStatus(406);
            result.setResult("注册失败");
        }
        return result;
    }

    //
    @Autowired
    private PayService payService;
    @Autowired
    private ShoppingAddressService shoppingAddressService;
    @Autowired
    private ShoppingTrolleyService shoppingTrolleyService;

    @RequestMapping("addOrder")
    public boolean addOrder(Order order){
        String ordernumber = ""+((int)(Math.random()*90000000)+10000000);
        order.setOrderNumber(ordernumber);
        System.out.println("==========");
        boolean b = orderService.addOrder(order);
        System.out.println(b+"aaaaaaaaaaaa");
        return b;
    }

    @RequestMapping("removeShoppingTrolley")
    public boolean removeShoppingTrolley(ShoppingTrolley shoppingTrolley){
        System.out.println(shoppingTrolley+"oooo");
        boolean b = shoppingTrolleyService.removeByUidAndFid(shoppingTrolley);
        System.out.println(b);
        return b;
    }



}
